package com.market.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.market.entity.Airport;

/**
 * Test connection
 * @author luunt
 *
 */
@Repository
@Transactional
public class AirportImpl extends AbstractJpaDao<Airport> implements AirportDao {
	
	@PersistenceContext
	private EntityManager em;

	public AirportImpl () {
		super (Airport.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Airport find(String airportId) {
		String sql = "select airport from Airport airport where airport.airportId = :airportId";
		Query query = em.createQuery(sql);
		query.setParameter("airportId", airportId);
		List<Airport> airports = (List<Airport>) query.getResultList();
		if (null != airports && airports.size() > 0) {
			return airports.get(0);
		}
		return null;
	}
	
	
}
